home *** CD-ROM | disk | FTP | other *** search
- /* CheckOut.c: CheckOut applet for ProjectDrag
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
-
- #include <Errors.h>
-
- #include "DSUserProcs.h"
- #include "SourceServer.h"
- #include "PDDialogs.h"
- #include "Comments.h"
- #include "TasksAndErrors.h"
- #include "FileCancel.h"
-
-
- void CheckOutFile(FSSpec *file);
-
-
- /* This routine is called for each file passed in the ODOC event. */
-
- pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
- {
- #pragma unused ( opening )
- #pragma unused ( userDataHandle )
-
- CheckOutFile(myFSSPtr);
- }
-
-
- void CheckOutFile(FSSpec *file)
- {
- Str63 userName;
- Str15 nickname;
- OSErr err;
- CKIDHandle theCKID;
- AEDesc command;
- Str255 comment;
- Str255 projectName;
-
- TaskStart(2001, 1, file->name, NULL, NULL, NULL);
-
- /* find the user name and initials */
- err = GetUserSettings(userName, nickname, false);
- if (err != noErr)
- {
- gDone = true;
- return;
- }
-
- /* get the CKID */
- err = ExtractCKID(file, &theCKID);
- if (err != noErr)
- {
- RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
- NULL, NULL, NULL);
- return;
- }
-
- /* make sure the file is checked in */
- if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
- {
- DisposeHandle((Handle)theCKID);
- RaiseErrorString(kProjectDragStrings, kNoCheckOutPermission, file->name,
- NULL, NULL, NULL);
- return;
- }
-
- /* get the checkout comment from the user */
- comment[0] = 0;
- if (!GetChangeComment(false, file->name, comment))
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* mount the project */
- err = MountProjectFromCKID(theCKID, projectName);
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* create a CheckOut -m command for SourceServer
- * CheckOut -m -cs <comment> -d <dir> -project <project> -u <user> <file>
- */
- err = CreateCommand(&command, "CheckOut");
- if (err == noErr)
- err = AddCStringArg(&command, "-m");
- if (err == noErr)
- err = AddCommentArg(&command, comment);
- if (err == noErr)
- err = AddDirArg(&command, file->vRefNum, file->parID);
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err == noErr)
- err = AddUserArg(&command, userName);
- if (err == noErr)
- err = AddPStringArg(&command, file->name);
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- AEDisposeDesc(&command);
- RaiseErrorNumber(err);
- return;
- }
-
- err = SendCommand(&command); /* send the command to SourceServer */
- if (err != noErr)
- {
- DisposeHandle((Handle)theCKID);
- return;
- }
-
- /* add the checkout comment to the file */
- err = AddCheckoutComment(file, userName, nickname, comment);
- if (err != noErr)
- {
- /* pop the current task and start a new one if user confirms cancel */
- if (!ResTextYesNo(kProjectDragStrings, kCheckoutCommentFailedCancel,
- file->name, NULL, NULL, NULL))
- {
- DisposeHandle((Handle)theCKID);
- RaiseErrorNumber(userCanceledErr);
- return;
- }
-
- TaskDone(); /* not really! */
- TaskStart(2001, 2, file->name, NULL, NULL, NULL);
- err = FileCancel(file, theCKID);
- DisposeHandle((Handle)theCKID);
- if (err != noErr) return;
- }
-
- /* modify the label to green (2) */
- SetFileLabel(file, 2, NULL);
-
- DisposeHandle((Handle)theCKID);
- TaskDone();
- }
-
-
- void DoFileMenu(short itemID)
- {
- if ( itemID == 1 )
- SelectFile(); // call file selection userProc
- else
- SendQuitToSelf(); // send self a 'quit' event
- }
-